/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.Servicios;

import Model.Beans.Institution;
import Model.Beans.Student;
import Model.Beans.User;
import Model.DAO.StudentDAO;
import Model.DAO.UserDAO;
import java.util.List;

/**
 *
 * @author Pashi
 */
public class StudentSrv {
    private StudentDAO sDAO = new StudentDAO();
    private UserDAO userDAO = new UserDAO();

     
    public void setStudent(Student newStudent){
        sDAO.insertar(newStudent);
    }
    
    public List<Student> getStudents() {
        User u = new User();
        u.setIduser(1);
        Institution i = new Institution();
        i.setIdinstitution(1);
        i.setUser(u);
        
        return sDAO.getAllStudents(i);
    }
    
    public void aprobar(User studentAprobado){
        userDAO.actualizar(studentAprobado);
    }
    
    public Student getStudentById(int idStudent){
        return sDAO.searchById(idStudent);
    }
    
    public Student getStudentById(String studentId){
        List<Student> students = sDAO.buscarEstudiante(studentId);
        return (!students.isEmpty()) ? students.get(0) : null;
    }
    
    public void deleteStudentById(String studentId) {
        List<Student> students = sDAO.buscarEstudiante(studentId);
        if (!students.isEmpty()) {
            Student studentToDelete = students.get(0);
            User userToDelete = studentToDelete.getUser();
            sDAO.borrar(studentToDelete);
            new UserDAO().borrar(userToDelete);
        }
    }
    
    public void updateStudent(Student student) {
        sDAO.actualizar(student);
    }
}
